package com.graduation_design.mapper;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.graduation_design.entity.AppProduct;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

/**
* @author 从南
* @description 针对表【app_product】的数据库操作Mapper
* @createDate 2024-02-16 18:15:58
* @Entity com.graduation_design.entity.AppProduct
*/
public interface AppProductMapper extends BaseMapper<AppProduct> {

    @Update("update app_product set stock = stock - #{quantity} where id = #{productId} and stock >= #{quantity}")
    int reduceStock(@Param("productId") Long productId, @Param("quantity")Integer quantity);

    @Update("update app_product set stock = stock + #{quantity} where id = #{productId} and stock >= 0")
    int releaseStock(@Param("productId") Long productId, @Param("quantity")Integer quantity);

    Page<AppProduct> pageWithCategory(Page page, @Param("name") String name, @Param("categoryId") Long categoryId);
}




